﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO;
using System.Diagnostics;
using SaxUtil;

///*
// * ToDo
// * 
// * ANTLR

//要素名->SQL


///**/**/**

//WHERE nodetable.path LIKE '/bib/#/title'

//# は *

//１、パーサジェネレータで単純なXPathの文法（/**/**, /**//** )を定義
//２、SQLの生成


// * 
// */


namespace SaxApplication3
{
	class Program
	{
		static void Main( string[] args )
		{
			Console.WriteLine( "input XML File location path: " );
			// string path = Console.ReadLine();

			const string INPUT_XML_PATH = @"Archive.xml";

			XmlReaderSettings setting = new XmlReaderSettings();
			setting.IgnoreComments = true;					// コメントの無視
			setting.IgnoreProcessingInstructions = true;			// 処理命令の無視
			setting.IgnoreWhitespace = true;				// 空白の無視

			XmlReader reader = XmlReader.Create( INPUT_XML_PATH, setting );

			SaxModel sax = new SaxModel();

			while( reader.Read() )
			{
				switch( reader.NodeType )
				{
					case XmlNodeType.Element:
						sax.StartElement( reader.Name, reader.Value, reader.IsEmptyElement );
						if( reader.MoveToFirstAttribute() )
						{
							do { sax.GetAttribute( reader.Name, reader.Value ); }
							while( reader.MoveToNextAttribute() );
						}
						break;

					case XmlNodeType.EndElement:
						sax.EndElement( reader.Name, reader.Value );
						break;

					case XmlNodeType.Text:
						sax.GetText( reader.Name, reader.Value );
						break;

					case XmlNodeType.Comment:
						sax.ProcessingInst( reader.Name, reader.Value );
						break;

					case XmlNodeType.ProcessingInstruction:
						sax.ProcessingInst( reader.Name, reader.Value );
						break;
				}
			}

			sax.EndDocument();
		}
	}
}